package interpreter

import "learning/gooop/behavioral_patterns/interpreter/tokens"

type tArrayStack struct {
	items []iStackNode
}


type iStackNode interface {
	IsToken() bool
	IsExpression() bool
}


func newArrayStack() *tArrayStack {
	return &tArrayStack{
		make([]iStackNode, 0),
	}
}

func (me *tArrayStack) Push(node iStackNode) {
	me.items = append(me.items, node)
}

func (me *tArrayStack) Size() int {
	return len(me.items)
}

func (me *tArrayStack) Peek() (bool,iStackNode) {
	if me.Size() <= 0 {
		return false, nil
	}
	return true, me.items[me.Size() - 1]
}

func (me *tArrayStack) Pop() (bool, iStackNode) {
	if me.Size() <= 0 {
		return false, nil
	}

	it := me.items[me.Size() - 1]
	me.items = me.items[:me.Size() - 1]
	return true, it
}

type tTokenNode struct {
	token tokens.Tokens
	value string
	from int
	to int
}

func newTokenNode(t tokens.Tokens, v string, from int, to int) *tTokenNode {
	return &tTokenNode{
		t,v, from, to,
	}
}


func (me *tTokenNode) IsToken() bool {
	return true
}

func (me *tTokenNode) IsExpression() bool {
	return false
}


type tExpressionNode struct {
	Expression IBoolExpression
}


func newExpressionNode(e IBoolExpression) *tExpressionNode {
	return &tExpressionNode{
		e,
	}
}


func (me *tExpressionNode) IsToken() bool {
	return false
}

func (me *tExpressionNode) IsExpression() bool {
	return true
}
